package com.wantup.remote.client;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.Socket;

/**
 * 客户端，用于显示从远程获取的图片
 *
 * @author wangshangyi
 * @version V1.0  2020/8/14 10:59
 */
public class Client extends JFrame {

    private java.net.Socket cs;
    private MyPanel mypanel;

    public Client() {
        mypanel = new MyPanel();
        this.getContentPane().add(mypanel);
        this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
    }

    public Socket getCs() {
        return cs;
    }

    public void setCs(Socket cs) {
        this.cs = cs;
    }

    public MyPanel getMypanel() {
        return mypanel;
    }

    public void setMypanel(MyPanel mypanel) {
        this.mypanel = mypanel;
    }

    //连接服务器获取图片并绘制
    public void drawImage() {
        try {
            cs = new java.net.Socket("192.168.0.106", 12000);
            BufferedImage image = javax.imageio.ImageIO.read(cs.getInputStream());
            mypanel.setImage(image);
            mypanel.repaint();
            cs.close();
        } catch (IOException e2) {
            e2.printStackTrace();
        }
    }

    public static void main(String[] args)
    {
        Client client = new Client();
        client.setSize(800, 800);
        client.drawImage();
        client.setVisible(true);
    }
}
